package com.aaa.tmr.controller;

import com.aaa.tmr.entity.DictionaryType;
import com.aaa.tmr.service.DictionaryTypeService;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.aaa.tmr.util.Result;
import com.aaa.tmr.util.ReturnStatus;

import javax.annotation.Resource;

/**
 * (DictionaryType)表控制层
 *
 * @author makejava
 * @since 2021-03-21 20:10:36
 */
@Controller
@RequestMapping("dictionaryType")
public class DictionaryTypeController {
    /**
     * 服务对象
     */
    @Resource
    private DictionaryTypeService dictionaryTypeService;

    /**
     * 跳转字典类型分页列表页面
     * @return 列表页面
     */
    @RequestMapping("toDictionaryType")
    public String toDictionaryType(){
        return "back/dictionaryType-page";
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public DictionaryType selectOne(Integer id) {
        return this.dictionaryTypeService.queryById(id);
    }

    /**
     * 通过实体作为筛选条件查询
     *
     * @return 对象列表
     */
    @RequestMapping("queryAll")
    @ResponseBody
    public Result<java.util.List> queryAll(Integer page, Integer limit, DictionaryType dictionaryType) {
        PageInfo pageInfo = dictionaryTypeService.queryAll(page, limit, dictionaryType);
        return new Result<>(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(),
                pageInfo.getTotal(),pageInfo.getList());
    }

    /**
     * 新增数据
     *
     * @param dictionaryType 实例对象
     * @return 实例对象
     */
    @RequestMapping("insert")
    @ResponseBody
    public Result<DictionaryType> insert(DictionaryType dictionaryType) {
        return new Result<>(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(),0L,
                this.dictionaryTypeService.insert(dictionaryType));
    }

    /**
     * 修改数据
     *
     * @param dictionaryType 实例对象
     * @return 实例对象
     */
    @DeleteMapping("update")
    @ResponseBody
    public Result<DictionaryType> update(DictionaryType dictionaryType) {
        return new Result<>(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(),0L,
                this.dictionaryTypeService.update(dictionaryType));
    }

    /**
     * 通过主键删除数据
     *
     * @param typeId 主键
     * @return 是否成功
     */
    @DeleteMapping("deleteById")
    @ResponseBody
    public Result<Boolean> deleteById(Integer typeId) {
        return new Result<>(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(),0L,
                this.dictionaryTypeService.deleteById(typeId));
    }

    /**
     * description: 字典类型删除方法
     * @param typeIds typeIds
     * @return Result<Integer>
     * @author Marko
     * @Date 2021/3/21 18:14
     **/
    @DeleteMapping("deleteByIds")
    @ResponseBody
    public Result<Integer> deleteByIds(String typeIds){
        return new Result<>(ReturnStatus.SUCCESS.getCode(),ReturnStatus.SUCCESS.getMessage()
                ,0L,dictionaryTypeService.deleteByIds(typeIds));
    }

}
